<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>react</title>
</head>
<body>
  <div id="root"></div>

  <script type="text/javascript" src="./components/react.development.js"></script>
  <script type="text/javascript" src="./components/react-dom.development.js"></script>
  <script type="text/javascript" src="./components/babel.min.js"></script>

  <script type="text/babel">
    // 组合组件
    function Welcome (props) {
      return <h1>Hello, {props.name}</h1>;
    }

    function App () {
      return (
        <div>
          <Welcome name="Sara" />
          <Welcome name="Cache" />
          <Welcome name="Edote" />
        </div>
      );
    }

    ReactDOM.render(
      <App />,
      document.getElementById('root')
    )

    // 复用组件 （抽取组件）
    function Avatar (props) {
      return (
        <img className="Avatar"
          src={props.user.avatarUrl}
          alt={props.user.name}
        />
      );
    }

    function UserInfo (props) {
      return (
        <div className="UserInfo">
          <Avatar user={props.user} />  
          <div className="UserInfo-name">
            {props.user.name}</div>
        </div>
      )
    }

    function Comment (props) {
      return (
        <div className="Comment">
          <UserInfo user={props.author} /> 
          <div className="Comment-text">
            {props.text}
          </div>
          <div className="Comment-date">
            {FormDate(props.date)}
            </div>
        </div>
      );
    }

    // 所有 React 组件都必须像纯函数一样保护它们的 props 不被更改
    
  </script>
</body>
</html>